$package('itsm.system');

itsm.system.buyMain=function(){
	this.opt='';
	return {
		//列表
		buyMainGrid:function(){
			var params = $.extend({},jqGridParams, {	
				url:'buyCredits!findBuyCreditsPager.action',
				caption:'EP交易记录',
				colNames:['ID','卖出会员','会员姓名(卖出)','卖出金额','状态','银行类型','银行账号','微信','手机号码','挂出时间','购买时间','买入会员','会员姓名(买入)'],
			 	colModel:[
			 	          {name:'id',align:'center'},
			 	          {name:'loginName',align:'center'},
			 	          {name:'loginUserName',align:'center'},
			 	          {name:'buyMoney',align:'center'},
			 	          {name:'status',align:'center',formatter:itsm.system.buyMain.statusFormatter},
			 	          {name:'accountType',align:'center'},
			 	          {name:'bankAccount',align:'center'},
			 	          {name:'weiXin',align:'center'},
			 	          {name:'mobileNo',align:'center'},
			 	          {name:'buyTime',align:'center',formatter:timeFormatter},
			 	          {name:'confirmTime',align:'center',formatter:timeFormatter},
			 	          {name:'operationsCenter',align:'center'},
			 	          {name:'operationsCenterUserName',align:'center'}
			 	          
			 	],
				jsonReader: $.extend(jqGridJsonReader, {id: "id"}),
				sortname:'status',
				toolbar:[true,"top"],
				sortorder:'asc',
				pager:'#buyMainPager'
				});
				$("#buyMainGrid").jqGrid(params);
				$("#buyMainGrid").navGrid('#buyMainPager',navGridParams);
				//列表操作项
				$("#t_buyMainGrid").css(jqGridTopStyles);
				$("#t_buyMainGrid").html($('#buyMainGridToolbar').html());
				
				//自适应宽度
				setGridWidth("#buyMainGrid","regCenter",10);
		},
		statusFormatter:function(v1,v2,v3){
			if(v1=='0'){
				return "等待买入";
			}
			if(v1=='1'){
				return "已买入,待确认";
			}
			if(v1=='2'){
				return "卖出成功";
			}
			if(v1=='4'){
				return "已取消卖出";
			}
		},
		//搜索
		searchBuy:function(){
			var sdata=$('#buyMain_search_form').getForm();
			var postData = $("#buyMainGrid").jqGrid("getGridParam", "postData");
			$.extend(postData,sdata);
			var _url = 'buyCredits!findBuyCreditsPager.action';
			$('#buyMainGrid').jqGrid('setGridParam',{url:_url}).trigger('reloadGrid',[{"page":"1"}]);
		},
		
		confirmBuy:function(){
			
			if(confirm("是否确定要确认收到款项?")){
				checkBeforeEditGrid('#buyMainGrid',function(rowData){
					$.post('buyCredits!creditsOpt.action','buyCreditsDTO.optType=confirmBackHesk&buyCreditsDTO.id='+rowData.id,function(data){
						alert(data);
						$('#buyMainGrid').trigger('reloadGrid');
					})
					
				});
			}
			
			
		},
		
		init:function(){
			itsm.system.buyMain.buyMainGrid();
		}
	}
	
}();

$(function(){
	itsm.system.buyMain.init();
});